package com.mall.gateway.filter;

import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ljr
 * @version 1.0
 * @description: guava 布隆过滤器
 * @date 2021/9/14 9:46
 */
public class BloomFilterTest {

    private static int size = 1000000;

    private static BloomFilter<Integer> bloomFilter = BloomFilter.create(Funnels.integerFunnel(), size,0.001);

    public static void main(String[] args) {

        for(int i = 0; i < size; i++){
            bloomFilter.put(i);
        }


        List<Integer> list = new ArrayList<>(20000);
        for(int i = size+1; i < size+20000; i++){
            if(bloomFilter.mightContain(i)){
                list.add(i);
            }
        }

        System.out.println("误判的概率："+list.size());

    }

}
